//------------------------------------------------------------------------------
// ex1.c
//
// A small programm used for converting small letters in uppercase ones.
//
//
// Group: Group 5854, study assistant Gernot Riegler
//
// Authors: Daniel Lobenwein 0513094
//
//
// Latest Changes: 31.10.2010 (by Daniel)
//------------------------------------------------------------------------------
//

#include <stdio.h>


//------------------------------------------------------------------------------
///A small function to print out the binary of the scanned letter.
///
///Needs one input: "letter", converts it to binary and prints it to stdout.
///
///Letter is shifted by one and is compared through "bitwise And" with 1 and the
///result is printed to stdout, as far as the counter i doesn't reach less
///than 0.
///
///@return always zero
//
void binaryPrint(char letter)
{
  int i;
  for(i=7;i>=0;--i)
    {
      printf("%d",((letter>>i)&1));
    }
      printf("\n");
}


//------------------------------------------------------------------------------
///A small function to convert "letter" to the uppercase one.
///
///Function needs two inputs: char letter and int bitmask. The function first
///checks if the variable "letter" is valid and goes on by XOR'ing letter
///with the variable "bitmask". Else it returns the unmodified letter.
///
///@return is variable letter (modified or unmodified)
//
char caseConverter(char letter, int bitmask)
{
  if (letter >= 'a' && letter <= 'z')
    {
      letter ^= bitmask;
      return letter;
    }
  else
      return letter;
}


//------------------------------------------------------------------------------
///The main function
///
///Main-function is used for printing out to stdout and reading in from stdin.
///
///@return always zero
//
int main()
{
  char letter;
  int bitmask = 1 << 5;

  printf("Please enter a character: ");
  scanf("%c", &letter);

  printf("Input:   ");
  binaryPrint(letter);

  printf("Bitmask: ");
  binaryPrint(bitmask);

  printf("Output:  ");
  binaryPrint(caseConverter(letter,bitmask));

  printf("Your result: %c\n",caseConverter(letter,bitmask));
  return 0;
}
